#include "mbutton.h"

MButton::MButton(QPushButton *parent) : QPushButton(parent)
{
    setButtonFile_status(BUTTON_STATUS_FILE_NO_CHANGED);
}

void MButton::setValue(const QString value)
{
    val = value;
    setText(get_limit_val());
}

QString MButton::getValue() const
{
    return val;
}

QString MButton::get_limit_val()
{
    int file_name_start_index = val.lastIndexOf("/");
    QString file_name = val.mid(file_name_start_index+1);
    return file_name;
}

button_status MButton::getButton_status()
{
    return status;
}

void MButton::setButtonFile_status(button_status bs)
{
    QString style = styleSheet();
    MStyle tmp_style(style);
    if (bs == BUTTON_STATUS_FILE_CHANGED || bs == BUTTON_STATUS_FILE_NO_CHANGED){
        status =  bs;
        if(bs == BUTTON_STATUS_FILE_CHANGED){
            tmp_style.SetStyle("background-color","rgb(204,255,255)");
        }
        else {
            tmp_style.SetStyle("background-color","rgb(255,255,255)");
        }
        setFlat(true);
    }
    if(bs == BUTTON_STATUS_FILE_CURRENT_SHOW || bs == BUTTON_STATUS_FILE_CURRENT_NOTSHOW){
        if (bs == BUTTON_STATUS_FILE_CURRENT_SHOW){
            tmp_style.SetStyle("border","1px solid red");
        }
        else{
            tmp_style.SetStyle("border", "none");
        }
    }
    style = tmp_style.GetStyle();
    setStyleSheet(style);

}

void MButton::mousePressEvent(QMouseEvent *event)
{
    emit MClicked(val);
}

void MButton::mouseDoubleClickEvent(QMouseEvent *event)
{
    emit MDoubleClicked(val);
}


